package com.example.delll.kugou.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public class MyViewPaper extends PagerAdapter {

    private List<View> myViewPaper;
    private List<String> myTitleList;

    public MyViewPaper(List<View> myViewPaper,List<String> myTitleList) {
        this.myViewPaper = myViewPaper;
        this.myTitleList = myTitleList;
    }

    @Override
    public int getCount() {
        return myViewPaper==null?0:myViewPaper.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        container.addView(myViewPaper.get(position));
        return myViewPaper.get(position);
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(myViewPaper.get(position));
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return myTitleList.get(position);
    }
}
